package com.dz.gateway.filter;

import java.io.InputStream;
import java.io.OutputStream;

import com.netflix.zuul.ZuulFilter;

public abstract class AbstractResponseFilter extends ZuulFilter {
	
	protected static final String SEND_ERROR_FILTER_RAN = "sendErrorFilter.ran";
	
	private ThreadLocal<byte[]> buffers = new ThreadLocal<byte[]>() {
		@Override
		protected byte[] initialValue() {
			return new byte[8192];
		}
	};
	
	protected void writeResponse(InputStream zin, OutputStream out) throws Exception {
		byte[] bytes = buffers.get();
		int bytesRead = -1;
		while ((bytesRead = zin.read(bytes)) != -1) {
			out.write(bytes, 0, bytesRead);
		}
	}
}
